/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.injection;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 *
 * @author User
 */
public class CallCtx {

    private static ApplicationContext ctx = null;

    public static Object getBean(ServletRequest request, String beanName) {
        if (ctx == null) {
            if (!(request instanceof HttpServletRequest)) {
                throw new IllegalArgumentException(
                        "Can only process HttpServletRequest");
            }
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            ctx = getContext(httpRequest);
        }

        Object obj = new Object();
        return obj;
    }
   
    public static ApplicationContext getContext(HttpServletRequest httpRequest) {
        return WebApplicationContextUtils.getRequiredWebApplicationContext(
                httpRequest.getSession().getServletContext());
    }
}
